package com.liuceng.zen.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.liuceng.zen.mapper.GdtAdGroupMapper;
import com.liuceng.zen.pojo.domain.GdtAdGroup;

@Service
public class GdtAdGroupService extends BaseService<GdtAdGroup> {
  @Autowired
  GdtAdGroupMapper adGroupMapper;


  /**
   * 通过campaignId查询广告组信息
   * 
   * @param campaignId
   * @return
   */
  @Transactional(readOnly = true)
  public List<GdtAdGroup> selectByCampaignId(Map<String, Integer> map) {
    return adGroupMapper.selectByCampaignId(map);
  }

  @Transactional(readOnly = true)
  public Integer countByMemberId(Integer memberId) {
    return adGroupMapper.countByMemberId(memberId, "ADSTATUS_NORMAL");
  }

  @Transactional(readOnly = true)
  public GdtAdGroup selectAdGroupByMemberId(Integer memberId) {
    GdtAdGroup gdtAdGroup = adGroupMapper.selectAdGroupByMemberId(memberId);
    if (gdtAdGroup == null) {
      return new GdtAdGroup();
    }
    return gdtAdGroup;
  }

  public List<GdtAdGroup> findFrontAdGroups(Integer memberId) {
    Map<String, Object> params = new HashMap<>();
    params.put("memberId", memberId);

    return adGroupMapper.findFrontAdGroups(params);
  }

  public List<GdtAdGroup> findFrontAdGroups(Integer memberId, Integer sitesetType) {
    Map<String, Object> params = new HashMap<>();
    params.put("memberId", memberId);
    params.put("sitesetType", sitesetType);
    return adGroupMapper.findFrontAdGroups(params);
  }

  public List<GdtAdGroup> findFrontAdGroupByCrtSize(Integer memberId, Integer crtSize) {

    Map<String, Object> params = new HashMap<>();
    params.put("memberId", memberId);
    params.put("crtSize", crtSize);
    return adGroupMapper.findFrontAdGroups(params);
  }
}
